package com.lingz.manager.modules.wuxue.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingz.manager.common.vo.PageVo;
import com.lingz.manager.common.utils.ResultUtil;
import com.lingz.manager.common.vo.Result;
import com.lingz.manager.modules.scheduled.NiuKangTask;
import com.lingz.manager.modules.wuxue.entity.RealTimeWeather;
import com.lingz.manager.modules.wuxue.service.RealTimeWeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.util.List;

/**
 * @author caiyixun
 */
@Slf4j
@RestController
@Api(description = "纽康设备实时气象数据管理接口")
@RequestMapping("/wuxue/realTimeWeather")
@Transactional
public class RealTimeWeatherController {

    @Autowired
    private RealTimeWeatherService realTimeWeatherService;

    @GetMapping("/findRealTimeWeatherList")
    @ApiOperation("不分页查询纽康设备实时气象数据")
    public Result<List<RealTimeWeather>> findRealTimeWeatherList(RealTimeWeather realTimeWeather) throws IOException {
//        NiuKangTask niuKangTask = new NiuKangTask();
//        niuKangTask.insertRealTimeWeatherData();
        return new ResultUtil<List<RealTimeWeather>>().setData(realTimeWeatherService.findListRealTimeWeather(realTimeWeather));
    }

     @GetMapping("/findRealTimeWeatherPage")
     @ApiOperation("分页查询纽康设备实时气象数据")
     public Result<Page<RealTimeWeather>> findRealTimeWeatherPage(RealTimeWeather realTimeWeather, PageVo pageVo){
         return new ResultUtil<Page<RealTimeWeather>>().setData(realTimeWeatherService.findPageRealTimeWeather(realTimeWeather,pageVo));
     }

     @PostMapping("/insertRealTimeWeather")
     @ApiOperation("新增纽康设备实时气象数据")
     public Result<String> insertCaseInfo(RealTimeWeather realTimeWeather){
         return new ResultUtil<String>().setData(realTimeWeatherService.addRealTimeWeather(realTimeWeather));
     }

     @PostMapping("/updateRealTimeWeather")
     @ApiOperation("修改纽康设备实时气象数据")
     public Result<String> updateCaseInfo(RealTimeWeather realTimeWeather){
         return new ResultUtil<String>().setData(realTimeWeatherService.editRealTimeWeather(realTimeWeather));
     }

     @DeleteMapping("/deleteRealTimeWeather")
     @ApiOperation("删除纽康设备实时气象数据")
     public Result<String> deleteRealTimeWeather(String[] ids){
         return new ResultUtil<String>().setData(realTimeWeatherService.deleteRealTimeWeather(ids));
     }

    @GetMapping("/findRealTimeWeatherById")
    @ApiOperation("获取一条信息")
    public Result<RealTimeWeather> findRealTimeWeatherById(String id){
        return new ResultUtil<RealTimeWeather>().setData(realTimeWeatherService.findRealTimeWeatherById(id));
    }

}
